package org.dreamwork.tools.code.analyzer.gui;

import org.dreamwork.injection.IObjectContext;
import org.dreamwork.tools.code.analyzer.core.FileStatistician;

import javax.swing.*;
import java.awt.event.*;

public class ModuleSettingDialog extends JDialog {
    private JPanel root;
    private JButton btnOK;
    private JButton btnCancel;
    private JTextField txtName;
    private JTextField txtLocation;
    private JButton btnBrowse;
    private JTextField txtIgnoredPattern;

    private IObjectContext context;

    public ModuleSettingDialog () {
        setContentPane (root);
        setModal (true);
        getRootPane ().setDefaultButton (btnOK);

        btnOK.addActionListener (e -> onOK ());

        btnCancel.addActionListener (e -> onCancel ());

        // call onCancel() when cross is clicked
        setDefaultCloseOperation (DO_NOTHING_ON_CLOSE);
        addWindowListener (new WindowAdapter () {
            public void windowClosing (WindowEvent e) {
                onCancel ();
            }
        });

        // call onCancel() on ESCAPE
        root.registerKeyboardAction (new ActionListener () {
            public void actionPerformed (ActionEvent e) {
                onCancel ();
            }
        }, KeyStroke.getKeyStroke (KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);

        txtIgnoredPattern.setText (FileStatistician.DEFAULT_IGNORED);
    }

    private void onOK () {
        // add your code here
        dispose ();
    }

    private void onCancel () {
        // add your code here if necessary
        dispose ();
    }

    public void setObjectContext (IObjectContext context) {
        this.context = context;
    }

    public static void main (String[] args) {
        ModuleSettingDialog dialog = new ModuleSettingDialog ();
        dialog.pack ();
        dialog.setVisible (true);
        System.exit (0);
    }
}